﻿using MediatR;
using Production_Get.API.Infrastructures.Interfaces;
using Return.Enum;
using THE_WIND_RISES.Common.Domans.Produce.Procurement;
using THE_WIND_RISES.Common.Dtos;

namespace Production_Get.API.Application.Commands.Warehousingtes
{
    /// <summary>
    /// 委托反填
    /// </summary>
    public class PurchasingsManHandler : IRequestHandler<PurchasingsManCommend, Result>
    {
        private readonly IBaseRepositoryGet<PurchasingsDto> PurchasingsDto;

        public PurchasingsManHandler(IBaseRepositoryGet<PurchasingsDto> PurchasingsDto)
        {
            this.PurchasingsDto = PurchasingsDto;
        }

        public async Task<Result> Handle(PurchasingsManCommend request, CancellationToken cancellationToken)
        {
            var result = new Result() { Code = (int)CommonErrorCodes.Search };

            string sql = "SELECT * FROM Purchasings a INNER JOIN Suppliers b on a.SuppliersId=b.SuppliersId where PurchasinId=" + request.PurchasinId;
            var list = PurchasingsDto.GetAll(sql, default).FirstOrDefault();
            if (list != null)
            {
                result.Code = (int)CommonErrorCodes.Success;
                result.Data = list;
                result.Msg = "反填成功";
            }

            return result;
        }
    }
}
